/*
 * @Author: huangtianyang 916072572@qq.com
 * @Date: 2023-08-21 14:52:04
 * @LastEditors: huangtianyang
 * @LastEditTime: 2023-10-26 11:06:23
 * @FilePath: \cxl-admin\src\pages\consumeManage\topUp\detailed\index.ts
 */
import { reactive, ref } from 'vue'
import * as tableConfig from './config.json'
import { BaseData, BaseMethod } from '@/utils/basc-data'
import { topUpList, topUpParamsInterface } from '@/apis/consume/topUp'
import { packageNameMap } from '@/utils/config'
import { CreateXMLHttpRequest } from '@/utils'

export default class TopUpDetailedData extends BaseData implements BaseMethod {
    dialog = reactive({
        visible: false,
        title: '',
        width: '70%',
        companyId: '',
        date: []
    })
    fromTo = reactive([])
    companyId = ref('')
    constructor() {
        super(tableConfig)
    }
    getData = (arg?: any) => {
        const obj: topUpParamsInterface = {
            current: this.pageData.pagination.pageNo,
            size: this.pageData.pagination.pageSize,
            companyId: this.dialog.companyId,
            payStatus: 1
        }

        topUpList(obj).then(res => {
            if (res.data.value === 200) {
                this.pageData.pagination.total = res.data.data.total
                this.pageData.table.data.length = 0

                res.data.data.records.forEach((item: any) => {
                    const str = Number(item.packageNameNumber) === 0 ? '单次' : ''
                    item.packageName = item.packageNameNumber
                        ? packageNameMap.get(item.packageNameNumber + '') + `（${item.amount}元/${item.freeCount}次）`
                        : str
                    this.pageData.table.data.push(item)
                })
            }
        })
    }
    onSearch = (arg?: any) => {}
    onReset = (arg?: any) => {}
    onPaginationChange = (arg?: any) => {
        this.pageData.pagination.pageNo = arg
        this.getData()
    }
    onPaginationSize = (arg?: any) => {
        this.pageData.pagination.pageNo = 1
        this.pageData.pagination.pageSize = arg
        this.getData()
    }
    onOperation = (arg?: any) => {
        const { type, data } = arg
        if (type === 'export') {
            const params = `current=99&size=99&companyId=${this.dialog.companyId}&payStatus=1`

            console.log('params', params)
            const url = import.meta.env.VITE_HOST + '/api/mall/company/store/store-order-list/export?' + params

            CreateXMLHttpRequest(url, this.dialog.title + '充值汇总列表')
        }
    }
}
